<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button onclick="sub()">发送数据到服务端</button>
  <script>
    let ws = new WebSocket('ws://localhost:8000');
    ws.onopen = function(){
      console.log('连接成功！');
    }

    ws.onmessage = function(event){
      let {data} = event;
      console.log(JSON.parse(data));
    }

    ws.onerror = function(err){
      console.log(err);
    }
    function sub(){
      console.log(11);
      ws.send('从客户端发过来的消息');
    }
  </script>
</body>
</html>